from peewee import *

# 基础配置
db = MySQLDatabase(
    "spider",
    host="127.0.0.1",
    port=3306,
    user='root',
    password="123456"
)


# 基础类
class BaseModel(Model):
    class Meta:
        database = db


"""
char类型，要设置最大长度，默认为255
对于无法确定最大长度的，可以设置为Text
设计表的时候，采集到的数据要尽量先做格式化处理
default 和 null=True
"""


class Topic(BaseModel):
    title = CharField()
    id = IntegerField(primary_key=True)
    author_id = CharField()
    create_time = DateTimeField()
    answer_nums = IntegerField(default=0)
    click_nums = IntegerField(default=0)
    score = IntegerField(default=0)  # 赏分
    status = CharField()  # 状态


class Answer(BaseModel):
    id = IntegerField(primary_key=True)
    topic_id = IntegerField()
    author_name = CharField()
    author_id = CharField()
    content = TextField(default="")
    create_time = DateTimeField()
    parised_nums = IntegerField(default=0)  # 点赞数


class Author(BaseModel):
    name = CharField()
    id = CharField(primary_key=True)
    blog_nums = IntegerField(default=0)  # 文章数
    follower_nums = CharField()  # 粉丝数
    following_nums = CharField()  # 关注数


if __name__ == "__main__":
    db.create_tables([Topic, Answer, Author])
    print('success')
